import com.sun.org.apache.regexp.internal.RE;

import java.util.Arrays;
import java.util.Scanner;

interface IntegerStack{
    public Integer push(Integer item);
//如果item为null，则不入栈直接返回null。如果栈满，也返回null。如果插入成功，返回item。

    public Integer pop();   //出栈，如果为空，则返回null。出栈时只移动栈顶指针，相应位置不置为null
    public Integer peek();  //获得栈顶元素，如果为空，则返回null.
    public boolean empty(); //如果为空返回true
    public int size();      //返回栈中元素个数
}
class ArrayIntegerStack implements IntegerStack{
    private int a[];
    private int end=0;

    public ArrayIntegerStack(int num) {
        a=new int[num];
    }

    @Override
    public Integer push(Integer item) {
        if (item==null){
            return null;
        }
        if (end==a.length){
            return null;
        }
        a[end]=item;
        end++;
        return item;
    }

    @Override
    public Integer pop() {
        if (end==0){
            return null;
        }
        end--;
        return a[end];
    }

    @Override
    public Integer peek() {
        if (end==0){
            return null;
        }
        return a[end-1];
    }

    @Override
    public boolean empty() {
        if (end==0){
            return true;
        }
        return false;
    }

    @Override
    public int size() {
        return end;
    }

    @Override
    public String toString() {
        String s="";
        int i=0;
        while (i<end-1){
            s+=a[i]+", ";
            i++;
        }
        if (end==0){
            while (i<a.length-1){
                s+="null, ";
                i++;
            }
            s+="null";
        }else {
            if (end<a.length){
                s+=a[i]+", ";
                for (int p=0;p<a.length-end-1;p++){
                    s+="null, ";
                }
                s+=null;
            }else {
                s+=a[i];
            }
        }

        return "["+s+"]";
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        ArrayIntegerStack arrayIntegerStack = new ArrayIntegerStack(sc.nextInt());
        int num=sc.nextInt();
        for(int i=0;i<num;i++){
            System.out.println(arrayIntegerStack.push(sc.nextInt()));
        }
        System.out.println(arrayIntegerStack.peek()+","+arrayIntegerStack.empty()+","+arrayIntegerStack.size());
        String arr=arrayIntegerStack.toString();
        System.out.println(arrayIntegerStack.toString());
        int time=sc.nextInt();
        for (int i=0;i<time;i++){
            System.out.println(arrayIntegerStack.pop());
        }
        System.out.println(arrayIntegerStack.peek()+","+arrayIntegerStack.empty()+","+arrayIntegerStack.size());
        System.out.println(arr);
    }
}
